#pragma once
#include "EngineObject.h"
#include "Texture.h"

namespace DreamEngine
{
class _EngineExport CTextureUnitState : public CEngineObject
{
public:

	enum TextureOpType
	{
		TEXTURE_OP_TYPE_COLOR,
		TEXTURE_OP_TYPE_ALPHA,
	};

	class _EngineExport LayerTextureOp
	{
	public:

		D3DTEXTUREOP				m_textureOp;
		DWORD						m_source1;
		DWORD						m_source2;

		LayerTextureOp(D3DTEXTUREOP textureOp=D3DTOP_ADD,\
			DWORD source1=D3DTA_TEXTURE, DWORD source2=D3DTA_CURRENT):
			m_textureOp(textureOp),
			m_source1(source1),
			m_source2(source2)
		{
			
		}
	};

	typedef	std::vector<std::pair<D3DTEXTURESTAGESTATETYPE,DWORD> > TextureStageStateLst;

public:
	CTextureUnitState(const std::string& name="", CTexture* pTexture=NULL);
	~CTextureUnitState(void);

	CTexture*		  GetTexture()const				{return m_pTexture;}
	void			  SetTexture(CTexture* pTexture);

	D3DTEXTUREADDRESS GetTextureAdress() const		{return m_textureAddressMode;}
	void SetTextureAdress(D3DTEXTUREADDRESS address);

	const LayerTextureOp& GetLayerColorOp(void)const	{return m_textureOp;}
	void SetColourOperation(D3DTEXTUREOP op, \
		DWORD source1=D3DTA_TEXTURE, DWORD source2 = D3DTA_CURRENT);
	void SetColourOperation(const LayerTextureOp& colorOp);

	bool GetColourOpEnable()const					{return m_colorOpEnable;}
	void SetColourOpEnable(bool isEnable);

	const LayerTextureOp& GetLayerAlphaOp(void)const	{return m_alphaOp;}
	void SetAlphaOperation(D3DTEXTUREOP op, \
		DWORD source1=D3DTA_TEXTURE, DWORD source2 = D3DTA_CURRENT);
	void SetAlphaOperation(const LayerTextureOp& alphaOp);

	bool GetAlphaOpEnable()const					{return m_alphaOpEnable;}
	void SetAlphaOpEnable(bool isEnable);

	void AddTextureStageStates(D3DTEXTURESTAGESTATETYPE stageType, DWORD vaule);
	const TextureStageStateLst& GetTextureStageStateLst(void)const		{return m_textureStageStates;}

protected:

	std::string					m_name;
	CTexture*					m_pTexture;
	//render state
	D3DTEXTUREADDRESS			m_textureAddressMode;
	
	LayerTextureOp				m_textureOp;
	LayerTextureOp				m_alphaOp;
	bool						m_colorOpEnable;
	bool						m_alphaOpEnable;

	TextureStageStateLst		m_textureStageStates;
};

}

